// AdapterControl.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "AdapterControl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//
//TODO: If this DLL is dynamically linked against the MFC DLLs,
//		any functions exported from this DLL which call into
//		MFC must have the AFX_MANAGE_STATE macro added at the
//		very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

// CAdapterControlApp

BEGIN_MESSAGE_MAP(CAdapterControlApp, CWinApp)
END_MESSAGE_MAP()


// CAdapterControlApp construction

CAdapterControlApp::CAdapterControlApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CAdapterControlApp object

CAdapterControlApp theApp;


// CAdapterControlApp initialization

BOOL CAdapterControlApp::InitInstance()
{
	CWinApp::InitInstance();

	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	return TRUE;
}

/*


void AdappterInfo_Init()
{
	PIP_ADAPTER_ADDRESSES pAddresses;

	ULONG outBufLen = 0;
	DWORD dwRetVal = 0;

    pAddresses = (IP_ADAPTER_ADDRESSES*) malloc(sizeof(IP_ADAPTER_ADDRESSES));

    // Make an initial call to GetAdaptersAddresses to get the 
    // size needed into the outBufLen variable
    if (GetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &outBufLen) 
        == ERROR_BUFFER_OVERFLOW) {
            free(pAddresses);
            pAddresses = (IP_ADAPTER_ADDRESSES*) malloc(outBufLen);
    }


    // Make a second call to GetAdapters Addresses to get the
    // actual data we want
    if ((dwRetVal = GetAdaptersAddresses(AF_INET, 
        0, 
        NULL, 
        pAddresses, 
        &outBufLen)) == NO_ERROR) {
            // If successful, output some information from the data we received
            PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;

}

}


int GetIPAddr(in_addr *addr)
{

	PIP_ADAPTER_ADDRESSES pAddresses;
    ULONG outBufLen = 0;
    DWORD dwRetVal = 0;

    pAddresses = (IP_ADAPTER_ADDRESSES*) malloc(sizeof(IP_ADAPTER_ADDRESSES));

    // Make an initial call to GetAdaptersAddresses to get the 
    // size needed into the outBufLen variable
    if (GetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &outBufLen)== ERROR_BUFFER_OVERFLOW) {
            free(pAddresses);
            pAddresses = (IP_ADAPTER_ADDRESSES*) malloc(outBufLen);
    }
	// Make a second call to GetAdapters Addresses to get the
    // actual data we want
    if ((dwRetVal = GetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &outBufLen)) == NO_ERROR) {
            // If successful, output some information from the data we received
            PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;
            while (pCurrAddresses) {
                printf("\tFriendly name: %S\n", pCurrAddresses->FriendlyName);
                printf("\tDescription: %S\n", pCurrAddresses->Description);
                pCurrAddresses = pCurrAddresses->Next;
            }
    }



    return 0;

}




int GetMACAddr(CString &szMAC)
{
	/*
            PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;
            while (pCurrAddresses) {
				            if (pCurrAddresses->PhysicalAddressLength != 0) {
								szMAC.Format(_T("%02X-%02X-%02X-%02X-%02X-%02X"),
									pCurrAddresses->PhysicalAddress[0],
									pCurrAddresses->PhysicalAddress[1],
									pCurrAddresses->PhysicalAddress[2],
									pCurrAddresses->PhysicalAddress[3],
									pCurrAddresses->PhysicalAddress[4],
									pCurrAddresses->PhysicalAddress[5]);

            }

          //      pCurrAddresses = pCurrAddresses->Next;
      //      }

	return 0;
}

int SetCurAdapIndex(int nIndex)
{


	return 0;
} */